
Page({

  /**
  * 页面的初始数据
  */
  data: {
  img: ['https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/27fc65decc5cd3e69d39792ccb451e9c.png', 
  'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/3cc3afc0aaae7c0498071532d0ca5ca8.png', 
  'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/5025888a884666835048797f487cc1e4.png', 
  'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/20c0b7f869ae03d0107785dbe15e95f8.png', 
  'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/3ef97abaa2f0bdaefbcbea619fad5baa.png',
   'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/3186ea8fb6d6c64398a8b59a1bea75cb.png'],
  playNum:null,
  companyData1:[
    {
     id:0,
     name:'产品1',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/27fc65decc5cd3e69d39792ccb451e9c.png'
    },
    {
     id:1,
     name:'产品2',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/5025888a884666835048797f487cc1e4.png'
    },
    {
     id:2,
     name:'产品3',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/3186ea8fb6d6c64398a8b59a1bea75cb.png'
    },
    {
     id:3,
     name:'产品4',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/3ef97abaa2f0bdaefbcbea619fad5baa.png'
    },
    {
     id:4,
     name:'产品5',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/20c0b7f869ae03d0107785dbe15e95f8.png'
    }
   ],
   companyData2:[
    {
     id:0,
     name:'产品1',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/27fc65decc5cd3e69d39792ccb451e9c.png'
    },
    {
     id:1,
     name:'产品2',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/5025888a884666835048797f487cc1e4.png'
    },
    {
     id:2,
     name:'产品3',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/3186ea8fb6d6c64398a8b59a1bea75cb.png'
    },
    {
     id:3,
     name:'产品4',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/3ef97abaa2f0bdaefbcbea619fad5baa.png'
    },
    {
     id:4,
     name:'产品5',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/20c0b7f869ae03d0107785dbe15e95f8.png'
    }
   ],
   companyData3:[
    {
     id:0,
     name:'产品1',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/27fc65decc5cd3e69d39792ccb451e9c.png'
    },
    {
     id:1,
     name:'产品2',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/5025888a884666835048797f487cc1e4.png'
    },
    {
     id:2,
     name:'产品3',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/3186ea8fb6d6c64398a8b59a1bea75cb.png'
    },
    {
     id:3,
     name:'产品4',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/3ef97abaa2f0bdaefbcbea619fad5baa.png'
    },
    {
     id:4,
     name:'产品5',
     img:'https://zhimi-lake.oss-cn-beijing.aliyuncs.com/images/20c0b7f869ae03d0107785dbe15e95f8.png'
    }
   ],

  },
  changes(e){
  //如果 play 等于null 第一次操作数组 否则 第二次
  if(this.data.playNum==null){
  this.setData({ one: e.currentTarget.dataset.index })
  let that = this
  wx.showActionSheet({
  itemList: ['操作', '迁至'],
  itemColor: '#007aff',
  success(res) {
  if (res.tapIndex==1){
  that.setData({ playNum: res.tapIndex })
  }
  }
  })
  }else{
  //第二次点击 交换
  this.setData({ two: e.currentTarget.dataset.index })
  if (this.data.playNum == 1) {
  let arr = this.data.img
  let x = this.data.one, y = this.data.two
  if (arr[y] == '') {
  arr.splice(x, 1, ...arr.splice(y, 1, arr[x]))
  // 交换后更新数组
  this.setData({
  img: arr,
  playNum:null,
  one:null,
  two:null
  })
  } else {
  wx.showToast({
  title: '已有',
  icon: 'none'
  })
  }
  }
  }
  
  },
  //位置向上移动
topClick1: function(e) {
  console.log('位置向上移动')
  var that = this
  var index = e.currentTarget.dataset.index
  console.log('位置向上移动 index='+index)

  var one = that.data.companyData1[index]
  var two = that.data.companyData1[index - 1]
  var index2 = index - 1
  var data1 = "companyData1[" + index + "]"
  var data2 = "companyData1[" + index2 + "]"
  that.setData({
   [data1]: two,
   [data2]: one
  })
  },
  
  // 城墙位置向下移动1
  bottomClick1: function(e) {
    console.log('位置向下移动')
  var that = this
  var index = e.currentTarget.dataset.index
  var id = e.currentTarget.dataset.id
  console.log('位置向下移动 index='+index +' id='+id)
  var one = that.data.companyData1[index]
  var two = that.data.companyData1[index + 1]
  var index2 = index + 1
  var data1 = "companyData1[" + index + "]"
  var data2 = "companyData1[" + index2 + "]"
  that.setData({
   [data1]: two,
   [data2]: one
  })
  var ids = '';
  that.data.companyData1.forEach(function(item, index){
    //console.log(item); 
    ids += item.id;
    console.log(JSON.stringify(item))
    console.log(ids); 
});
  
  },
   
  // 位置向下移动2
  bottomClick2: function(e) {
    console.log('位置向下移动2')
  var that = this
  var index = e.currentTarget.dataset.index
  var id = e.currentTarget.dataset.id
  console.log('位置向下移动2 index='+index +' id='+id)
  var one = that.data.companyData2[index]
  var two = that.data.companyData2[index + 1]
  var index2 = index + 1
  var data1 = "companyData2[" + index + "]"
  var data2 = "companyData2[" + index2 + "]"
  that.setData({
   [data1]: two,
   [data2]: one
  })
  },
  // 位置向下移动3
  bottomClick3: function(e) {
    console.log('位置向下移动3')
  var that = this
  var index = e.currentTarget.dataset.index
  var id = e.currentTarget.dataset.id
  console.log('位置向下移动3 index='+index +' id='+id)
  var one = that.data.companyData3[index]
  var two = that.data.companyData3[index + 1]
  var index2 = index + 1
  var data1 = "companyData3[" + index + "]"
  var data2 = "companyData3[" + index2 + "]"
  that.setData({
   [data1]: two,
   [data2]: one
  })
  }



  })
  